package com.lam.mall.service.impl;

import java.util.List;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.utils.StringUtils;
import com.lam.mall.entity.ProdSpecsValue;
import com.lam.mall.mapper.ProdSpecsValueMapper;
import com.lam.mall.param.ProdSpecsValueParam;
import com.lam.mall.service.ProdSpecsValueService;

/**
 * 规格值管理Service业务层处理
 * 
 * @author admin
 * @date 2023-04-21
 */
@Service
public class ProdSpecsValueServiceImpl  implements ProdSpecsValueService {

    @Autowired
    private ProdSpecsValueMapper prodSpecsValueMapper;

    /**
     * 查询规格值管理
     * 
     * @param id ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public ProdSpecsValue selectById(String id) {

        return prodSpecsValueMapper.selectById(id);
    }

    /**
     * 查询规格值管理列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<ProdSpecsValue> selectList(ProdSpecsValueParam param) {
    
        QueryWrapper<ProdSpecsValue> queryWrapper = new QueryWrapper<>();
        
        queryWrapper.eq(Objects.nonNull(param.getSpecsId()), "specs_id", param.getSpecsId());

        return prodSpecsValueMapper.selectList(queryWrapper);
    }

    /**
     * 新增规格值管理
     * 
     * @param prodSpecsValue 
     * @return 
     */
    @Override
    @Transactional
    public int insert(ProdSpecsValue prodSpecsValue) {
    
        return prodSpecsValueMapper.insert(prodSpecsValue);
    }

    /**
     * 修改规格值管理
     * 
     * @param prodSpecsValue 
     * @return 
     */
    @Override
    @Transactional
    public int update(ProdSpecsValue prodSpecsValue) {
    
        return prodSpecsValueMapper.updateById(prodSpecsValue);
    }

    /**
     * 删除规格值管理信息
     * 
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(String idStr) {
    
        if(StringUtils.isBlank(idStr)) {
            return 0;
        }
        return prodSpecsValueMapper.deleteBatchIds(StringUtils.str2List(idStr));
    }

	@Override
	public Long listSpecMaxValueId() {
		ProdSpecsValue propValue = prodSpecsValueMapper.selectOne(new LambdaQueryWrapper<ProdSpecsValue>()
                .orderByDesc(ProdSpecsValue::getId).last("limit 1"));
        return Objects.isNull(propValue) ? 0L : Long.valueOf(propValue.getId());
	}
    
    
}
